package com.v1.model;

import org.apache.commons.lang.StringUtils;

import com.v1.cache.CategoryCache;
import com.v1.util.Toolkit;

public abstract class BaseElement extends BaseModel {
	public static String NOT_EXIST_THUMB = null;

	private String link;
	private String rootName;
	private Category category;
	private Category root;
	private Integer categoryid;
	protected String href;

	public Category getCategory() {
		if (category == null) {
			CategoryCache categoryCache = (CategoryCache) Toolkit.getInstance().getBean("CategoryCache");
			category = categoryCache.get(categoryid);
		}
		return category;
	}

	public Category getRoot() {
		if (root == null) {
			CategoryCache categoryCache = (CategoryCache) Toolkit.getInstance().getBean("CategoryCache");
			root = categoryCache.getRoot(categoryid);
		}
		return root;
	}

	public String getRootName() {
		if (StringUtils.isEmpty(rootName)) {
			getRoot();
			rootName = root.getName();
		}
		return rootName;
	}

	public Integer getCategoryid() {
		return categoryid;
	}

	public void setCategoryid(Integer categoryid) {
		this.categoryid = categoryid;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getHref() {
		if (StringUtils.isEmpty(href)) {
			Integer rootcategoryid = getRoot().getCategoryid();
			if (rootcategoryid == 1) {
				href = "around";
			} else if (rootcategoryid == 3) {
				href = "hezuoshe";
			} else if (rootcategoryid == 4) {
				href = "others";
			}
			href += "/category.html?categoryid=" + categoryid;
		}
		return href;
	}

}
